home *** CD-ROM | disk | FTP | other *** search
- drop table Users
- go
-
- create table Users(
- UserID int not null identity,
- Username char(30) not null,
- FirstName char(20) not null default '',
- LastName char(20) not null default '',
- DateLastLogin datetime null,
- DateLastPasswordChange datetime null,
- PasswordLifespan smallint null,
- )
- GO
- grant all on Users to Public
- GO
-
-
- drop table AdminConfig
- go
-
- create table AdminConfig(
- PasswordLifespan smallint null,
- MustChangeNewPassword char(1) not null default 'N'
- check (MustChangeNewPassword in ('Y', 'N'))
- )
- GO
- grant all on AdminConfig to Public
- GO
- insert AdminConfig (MustChangeNewPassword) values ('N')
- go
-
-
- drop procedure AddUser
- go
- create procedure AddUser(
- @Username varchar(30),
- @Password varchar(30),
- @FirstName varchar(20),
- @LastName varchar(20),
- @PasswordLifespan smallint,
- @PasswordMustChange char(1) /* Y/N */
- )
- as
- declare @Result integer
- declare @DateLastPasswordChange datetime
- begin
- /* add a server login */
- execute @Result = sp_addlogin @Username, @Password
- if @Result = 0
- begin
- /* add the user to our database */
- execute @Result = sp_adduser @Username
- if @Result <> 0
- begin
- execute sp_droplogin @Username
- return
- end
-
- if @PasswordLifespan <= 0
- select @PasswordLifespan = null
-
- if Upper(@PasswordMustChange) = 'Y'
- select @DateLastPasswordChange = null
- else
- select @DateLastPasswordChange = GetDate()
-
- /* build a record for the supplementary user table */
- insert Users(Username, FirstName, LastName,
- PasswordLifespan, DateLastPasswordChange)
- values (@Username, @FirstName, @LastName,
- @PasswordLifespan, @DateLastPasswordChange)
-
- /* if an error, then remove the user from the system */
- if @@error <> 0
- begin
- execute sp_dropuser @Username
- execute sp_droplogin @Username
- end
- end
- end
- go
-
- drop procedure EditUser
- go
- create procedure EditUser(
- @Username varchar(30),
- @Password varchar(30),
- @FirstName varchar(20),
- @LastName varchar(20),
- @PasswordLifespan smallint,
- @PasswordMustChange char(1) /* Y/N */
- )
- as
- declare @Result integer
- declare @DateLastPasswordChange datetime
- begin
- if @Password <> ''
- begin
- execute @Result = sp_password null, @Password, @Username
- if @Result <> 0
- begin
- raiserror 50001 "Could not change user password"
- return
- end
- end
-
- if @PasswordLifespan <= 0
- select @PasswordLifespan = null
-
- if Upper(@PasswordMustChange) = 'Y'
- select @DateLastPasswordChange = null
- else
- select @DateLastPasswordChange = GetDate()
-
- /* change the Users record */
- update Users set
- FirstName = @FirstName,
- LastName = @LastName,
- PasswordLifespan = @PasswordLifespan,
- DateLastPasswordChange = @DateLastPasswordChange
- where Username = @Username
- end
- go
-
-